package pers.twm.mybatis.provider;

import com.intellij.execution.filters.ConsoleFilterProvider;
import com.intellij.execution.filters.Filter;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.NotNull;
import pers.twm.mybatis.provider.filter.MyBatisSqlLogConsoleFilter;

import java.util.Objects;

/**
 * @ClassName MyBatisLogConsoleFilterProvider
 * @Description TODO
 * @Author tianwanming
 * @Date 2023/2/26 21:16
 * @Version 1.0
 */
public class SqlLogConsoleFilterProvider implements ConsoleFilterProvider {

    private final Key<MyBatisSqlLogConsoleFilter> key = Key.create(MyBatisSqlLogConsoleFilter.class.getName());

    @Override
    @NotNull
    public Filter [] getDefaultFilters(@NotNull Project project) {

        MyBatisSqlLogConsoleFilter consoleFilter = project.getUserData(key);

        if(Objects.isNull(consoleFilter)) {
            consoleFilter = new MyBatisSqlLogConsoleFilter(project);
            project.putUserData(key, consoleFilter);
        }

        return new Filter[] {consoleFilter};
    }
}
